<?php

/*
Zoo Management Simulation
This file provides editing functionality allowing the user to edit an entry in the database.
The layout is the same as the addCage file and already has values selected when it is loaded
*/

include("dbconnect.php");
$cageid = $_REQUEST['cageid'];

$sql = "SELECT * FROM cage WHERE Cage_Id=".$cageid;
$result = mysql_query($sql);

while(($row = mysql_fetch_row($result)) !== FALSE)
	{
		$name = $row[1];
		$length = $row[2];
		$width = $row[3];
		$height = $row[4];
		$typeid = $row[5];
		$exhibitname = $row[6];
		$exhibitdesc = $row[7];
		$humandetector = $row[8];
	}
	
$typeSql = "SELECT Type_Desc FROM type WHERE Type_Id=".$typeid;
$typeresult = mysql_query($typeSql);
while(($typerow = mysql_fetch_row($typeresult)) !== FALSE)
	{
		$typedesc = $typerow[0];
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Cage</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Edit Cage</h1>

<form id="editCageForm" name="editCageForm" method="post" enctype="multipart/form-data" action="editCageEntry.php">

<table id="zootable" width="100%" border="1">
  <tr>
    <td id="tableheader"><label for="name">Name</label></td>
    <td id="tableheader"><label for="length">Length</label></td>
    <td id="tableheader"><label for="width">Width</label></td>
    <td id="tableheader"><label for="height">Height</label></td>
    <td id="tableheader"><label for="type">Type</label></td>
    <td id="tableheader"><label for="exhibitname">Exhibit Name</label></td>
    <td id="tableheader"><label for="exhibitdesc">Exhibit Description</label></td>
    <td id="tableheader"><label for="humandetector">Human Detector</label></td>
  </tr>
  
  <tr>
  <?php
    echo '<td><input type="range" name="name" id="name" value="'.$name.'" /></td>';
    echo '<td><input type="number" name="length" id="length" value="'.$length.'" /></td>';
    echo '<td><input type="number" name="width" id="width" value="'.$width.'" /></td>';
    echo '<td><input type="number" name="height" id="height" value="'.$height.'" /></td>';
    echo '<td><input type="radio" value="Open Enclosure" name="type" id="type" />Open Enclosure<br />';
    echo '<input type="radio" value="Glass" name="type" id="type" />Glass<br />';
    echo '<input type="radio" value="Bar" name="type" id="type" />Bar<br />';
    echo '<input type="radio" value="Wire" name="type" id="type" />Wire</td>';
    echo '<td><input type="text" name="exhibitname" id="exhibitname" value="'.$exhibitname.'" /></td>';
    echo '<td><input type="text" name="exhibitdesc" id="exhibitdesc" value="'.$exhibitdesc.'" /></td>';
	echo '<td><input type="radio" value="Human Inside" name="humandetector" id="humandetector" />Human Inside<br />';
    echo '<input type="radio" value="No Human Inside" name="humandetector" id="humandetector" />No Human Inside</td>';
	echo "<input type='hidden' name='cageid' value='".$cageid . "' />";
  ?>
  </tr>
</table>
<br />
<input type="submit" name="submit" id="submit" value="Edit Cage" />
<input type="submit" name="submit" id="submit" value="Return to Administator page" />
</form>
</body>
</html>